﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OracleClient;
using DBUtility;


namespace OracleDAL.SUBSYSTEM
{
  /// <summary>
	/// 数据访问类SUBSYS_STATISTICALPARAMETER。
	/// </summary>
	public class SUBSYS_STATISTICALPARAMETER
	{
		public SUBSYS_STATISTICALPARAMETER()
		{}
		#region  成员方法

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string SUBSYSTEMID,string PARAMETERNAME)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from SUBSYS_STATISTICALPARAMETER");
			strSql.Append(" where SUBSYSTEMID=:SUBSYSTEMID and PARAMETERNAME=:PARAMETERNAME ");
			OracleParameter[] parameters = {
					new OracleParameter(":SUBSYSTEMID", OracleType.VarChar,50),
					new OracleParameter(":PARAMETERNAME", OracleType.VarChar,50)};
			parameters[0].Value = SUBSYSTEMID;
			parameters[1].Value = PARAMETERNAME;

			return OracleHelper.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add(Model.SUBSYSTEM.SUBSYS_STATISTICALPARAMETER model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into SUBSYS_STATISTICALPARAMETER(");
			strSql.Append("SUBSYSTEMID,PARAMETERNAME,TABLENAME,TABLENAMEFIELD,METHOD)");
			strSql.Append(" values (");
			strSql.Append(":SUBSYSTEMID,:PARAMETERNAME,:TABLENAME,:TABLENAMEFIELD,:METHOD)");
			OracleParameter[] parameters = {
					new OracleParameter(":SUBSYSTEMID", OracleType.VarChar,25),
					new OracleParameter(":PARAMETERNAME", OracleType.VarChar,50),
					new OracleParameter(":TABLENAME", OracleType.VarChar,50),
					new OracleParameter(":TABLENAMEFIELD", OracleType.VarChar,50),
					new OracleParameter(":METHOD", OracleType.VarChar,500)};
			parameters[0].Value = model.SUBSYSTEMID;
			parameters[1].Value = model.PARAMETERNAME;
			parameters[2].Value = model.TABLENAME;
			parameters[3].Value = model.TABLENAMEFIELD;
			parameters[4].Value = model.METHOD;

			OracleHelper.ExecuteSql(strSql.ToString(),parameters);
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public void Update(Model.SUBSYSTEM.SUBSYS_STATISTICALPARAMETER model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update SUBSYS_STATISTICALPARAMETER set ");
			strSql.Append("TABLENAME=:TABLENAME,");
			strSql.Append("TABLENAMEFIELD=:TABLENAMEFIELD,");
			strSql.Append("METHOD=:METHOD");
			strSql.Append(" where SUBSYSTEMID=:SUBSYSTEMID and PARAMETERNAME=:PARAMETERNAME ");
			OracleParameter[] parameters = {
					new OracleParameter(":SUBSYSTEMID", OracleType.VarChar,25),
					new OracleParameter(":PARAMETERNAME", OracleType.VarChar,50),
					new OracleParameter(":TABLENAME", OracleType.VarChar,50),
					new OracleParameter(":TABLENAMEFIELD", OracleType.VarChar,50),
					new OracleParameter(":METHOD", OracleType.VarChar,500)};
			parameters[0].Value = model.SUBSYSTEMID;
			parameters[1].Value = model.PARAMETERNAME;
			parameters[2].Value = model.TABLENAME;
			parameters[3].Value = model.TABLENAMEFIELD;
			parameters[4].Value = model.METHOD;

			OracleHelper.ExecuteSql(strSql.ToString(),parameters);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public void Delete(string SUBSYSTEMID,string PARAMETERNAME)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from SUBSYS_STATISTICALPARAMETER ");
			strSql.Append(" where SUBSYSTEMID=:SUBSYSTEMID and PARAMETERNAME=:PARAMETERNAME ");
			OracleParameter[] parameters = {
					new OracleParameter(":SUBSYSTEMID", OracleType.VarChar,50),
					new OracleParameter(":PARAMETERNAME", OracleType.VarChar,50)};
			parameters[0].Value = SUBSYSTEMID;
			parameters[1].Value = PARAMETERNAME;

			OracleHelper.ExecuteSql(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Model.SUBSYSTEM.SUBSYS_STATISTICALPARAMETER GetModel(string SUBSYSTEMID,string PARAMETERNAME)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select SUBSYSTEMID,PARAMETERNAME,TABLENAME,TABLENAMEFIELD,METHOD from SUBSYS_STATISTICALPARAMETER ");
			strSql.Append(" where SUBSYSTEMID=:SUBSYSTEMID and PARAMETERNAME=:PARAMETERNAME ");
			OracleParameter[] parameters = {
					new OracleParameter(":SUBSYSTEMID", OracleType.VarChar,50),
					new OracleParameter(":PARAMETERNAME", OracleType.VarChar,50)};
			parameters[0].Value = SUBSYSTEMID;
			parameters[1].Value = PARAMETERNAME;

			Model.SUBSYSTEM.SUBSYS_STATISTICALPARAMETER model=new Model.SUBSYSTEM.SUBSYS_STATISTICALPARAMETER();
			DataSet ds=OracleHelper.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				model.SUBSYSTEMID=ds.Tables[0].Rows[0]["SUBSYSTEMID"].ToString();
				model.PARAMETERNAME=ds.Tables[0].Rows[0]["PARAMETERNAME"].ToString();
				model.TABLENAME=ds.Tables[0].Rows[0]["TABLENAME"].ToString();
				model.TABLENAMEFIELD=ds.Tables[0].Rows[0]["TABLENAMEFIELD"].ToString();
				model.METHOD=ds.Tables[0].Rows[0]["METHOD"].ToString();
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select SUBSYSTEMID,PARAMETERNAME,TABLENAME,TABLENAMEFIELD,METHOD ");
			strSql.Append(" FROM SUBSYS_STATISTICALPARAMETER ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return OracleHelper.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			OracleParameter[] parameters = {
					new OracleParameter(":tblName", OracleType.VarChar, 255),
					new OracleParameter(":fldName", OracleType.VarChar, 255),
					new OracleParameter(":PageSize", OracleType.Number),
					new OracleParameter(":PageIndex", OracleType.Number),
					new OracleParameter(":IsReCount", OracleType.Clob),
					new OracleParameter(":OrderType", OracleType.Clob),
					new OracleParameter(":strWhere", OracleType.VarChar,1000),
					};
			parameters[0].Value = "SUBSYS_STATISTICALPARAMETER";
			parameters[1].Value = "ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return OracleHelper.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  成员方法
	}
}

